﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ContactInformation", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(ContactInformation))]
    public class ContactInformationSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IContactInformation clazz;
        
        public ContactInformationSerializer(IContactInformation clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ContactType");
            if (clazz.ContactType!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "ContactType");
                Writer.WriteString(clazz.ContactType.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ContactType");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("ContactContent");
            if (clazz.ContactContent!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.ContactContent.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ContactContent");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Correspondence");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Correspondence))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ContactType") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ContactInformation>ContactType");
                }
                clazz.ContactType = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.ContactType(Reader.ReadElementString("ContactType"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ContactInformation>ContactType", Reader.LocalName);
            }
            if (Reader.LocalName=="ContactContent") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ContactInformation>ContactContent");
                }
                clazz.ContactContent = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("ContactContent"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ContactInformation>ContactContent", Reader.LocalName);
            }
            if (Reader.LocalName=="Correspondence") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ContactInformation>Correspondence");
                }
                clazz.Correspondence = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("Correspondence")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ContactInformation>Correspondence", Reader.LocalName);
            }
        }
    }
}
